import request from '@/utils/request'

// 查询订单查询列表
export function listOrders(query) {
  return request({
    url: '/order/orders/list',
    method: 'get',
    params: query
  })
}

// 查询订单查询详细
export function getOrders(orderId) {
  return request({
    url: '/order/orders/' + orderId,
    method: 'get'
  })
}

// 新增订单查询
export function addOrders(data) {
  return request({
    url: '/order/orders',
    method: 'post',
    data: data
  })
}

// 修改订单查询
export function updateOrders(data) {
  return request({
    url: '/order/orders',
    method: 'put',
    data: data
  })
}

// 删除订单查询
export function delOrders(orderId) {
  return request({
    url: '/order/orders/' + orderId,
    method: 'delete'
  })
}

// 根据店铺ID查询今日支付的订单数量
export function getTodayPaidOrderCount(shopId) {
  return request({
    url: '/order/orders/todayPaidCount/' + shopId,
    method: 'get'
  })
}

// 根据店铺ID查询今日商家实际收入
export function getTodayBusinessIncome(shopId) {
  return request({
    url: '/order/orders/todayBusinessIncome/' + shopId,
    method: 'get'
  })
}

// 根据店铺ID查询未到账的订单总数
export function getUnpaidToMerchantOrderCount(shopId) {
  return request({
    url: '/order/orders/unpaidToMerchantCount/' + shopId,
    method: 'get'
  })
}

// 根据店铺ID查询已售后的订单总数
export function getAfterSalesOrderCount(shopId) {
  return request({
    url: '/order/orders/afterSalesCount/' + shopId,
    method: 'get'
  })
}

// 根据店铺ID查询待支付订单数量
export function getPendingPaymentOrderCount(shopId) {
  return request({
    url: '/order/orders/pendingPaymentCount/' + shopId,
    method: 'get'
  })
}

// 根据店铺ID查询待配送订单数量
export function getPendingDeliveryOrderCount(shopId) {
  return request({
    url: '/order/orders/pendingDeliveryCount/' + shopId,
    method: 'get'
  })
}

// 根据店铺ID查询已完成订单数量
export function getCompletedOrderCount(shopId) {
  return request({
    url: '/order/orders/completedCount/' + shopId,
    method: 'get'
  })
}

// 根据店铺ID查询售后处理中订单数量
export function getAfterSalesProcessingOrderCount(shopId) {
  return request({
    url: '/order/orders/afterSalesProcessingCount/' + shopId,
    method: 'get'
  })
}

// ====== 指数统计相关API ======

// 根据店铺ID查询今日订单总数（所有状态）
export function getTodayAllOrderCount(shopId) {
  return request({
    url: '/order/orders/todayAllCount/' + shopId,
    method: 'get'
  })
}

// 根据店铺ID查询待处理订单总数（待支付+待配送）
export function getPendingOrderCount(shopId) {
  return request({
    url: '/order/orders/pendingCount/' + shopId,
    method: 'get'
  })
}

// 根据店铺ID查询本月订单总数
export function getMonthOrderCount(shopId) {
  return request({
    url: '/order/orders/monthCount/' + shopId,
    method: 'get'
  })
}

// 根据店铺ID查询订单总数（用于计算完成率）
export function getAllOrderCount(shopId) {
  return request({
    url: '/order/orders/allCount/' + shopId,
    method: 'get'
  })
}

// ====== 图表数据相关API ======

// 根据店铺ID和日期范围查询每日订单数量
export function getDailyOrdersChart(shopId, startDate, endDate) {
  return request({
    url: '/order/orders/dailyOrdersChart/' + shopId,
    method: 'get',
    params: {
      startDate,
      endDate
    }
  })
}

// ====== 订单统计相关API ======

// 根据店铺ID查询订单统计数据（本月、本周、上月、上周）
export function getOrderStats(shopId) {
  return request({
    url: '/order/orders/orderStats/' + shopId,
    method: 'get'
  })
}
